package com.cn.wanxi.service.impl;

import com.cn.wanxi.dao.IProductTypeDao;
import com.cn.wanxi.dao.impl.ProductTypeDaoImpl;
import com.cn.wanxi.model.ProductTypeModel;
import com.cn.wanxi.service.IProductTypeService;
import redis.clients.jedis.Jedis;

import java.util.List;

public class ProductTypeServiceImpl implements IProductTypeService {

    IProductTypeDao productTypeDao = new ProductTypeDaoImpl();

    @Override
    public List<ProductTypeModel> getProductTypeList() {
        Jedis jedis = new Jedis();
        if (jedis.exists("product_type_id")){
            return productTypeDao.getProductTypeListByRedis();
        }else {
            List<ProductTypeModel> list = productTypeDao.getProductTypeList();
            productTypeDao.setProductTypeInRedis(list);
            return list;
        }
    }

    @Override
    public ProductTypeModel getProductType(int id) {
        return productTypeDao.getProductType(id);
    }

    @Override
    public int addProductType(ProductTypeModel productType) {
        return productTypeDao.addProductType(productType);
    }

    @Override
    public int deleteProductType(int id) {
        return productTypeDao.deleteProductType(id);
    }

    @Override
    public int updateProductType(ProductTypeModel productType) {
        return productTypeDao.updateProductType(productType);
    }

    @Override
    public List<ProductTypeModel> getProductTypeList(int page, int size) {
        return productTypeDao.getProductTypeList(page,size);
    }

    @Override
    public List<ProductTypeModel> getProductTypeList(int page, int size, String sort) {
        return productTypeDao.getProductTypeList(page, size, sort);
    }

    @Override
    public List<ProductTypeModel> searchProductType(String sql) {
        return productTypeDao.searchProductType(sql);
    }

    @Override
    public long getProductTypeCount() {
        return productTypeDao.getProductTypeCount();
    }

    @Override
    public int updateEnable(int id, int enable) {
        return productTypeDao.updateEnable(id,enable);
    }
}
